<?php
   require_once "controller.php";
   require_once "home/model/IndexModel.php";
   require_once "Common/ConnDB.php";
   class IndexController extends Controller{
   	   function __construct(){
        parent::__construct();
   	   	$this->mod=new IndexModel();
   	   }
       //首页
       public function index(){
        $this->display();
       }
       //用户注册页
       public function userReg(){
        $this->display();
       }
       //用户登录
       public function userlog(){
        $this->display();
       }
       //管理员登录
       public function adminlog(){
        $this->display();
       }
       //选择试卷类型页面
       public function start(){

        $data=$this->mod->getTestList();//获取试卷类型数据


        $this -> assign("test",$data);
        $this->display();
       }

       public function usertest()
      {
        $data = $this -> mod -> getTestByID();
        $this -> assign("test",$data);
        $this -> display();
      }
       //内容页
       public function content(){
       
      }
      //添加用户
      public function adduser()
        {
          $result=$this->mod->addUserInfo($_POST);
          if($result == true)
          {
            echo "注册用户成功！";
            echo '<a href="index.php?c=index&m=userlog">如果没有跳转，请点这里跳转</a>';
            header("refresh:3;url='index.php?c=index&m=userlog'");
          }
          else
          {
            //header("location:index.php?c=index&m=listusers");
            echo '添加失败！';
          }
          
        }
        //用户登录
      public function doLogin()
        {
          $result = $this -> mod ->doLoginInfo($_POST);
          if($result == true)
          {
            //var_dump($result);
            session_start();
            //$sid = $_POST['sid'];
            //$sql = "select * from student where sid='$sid'";
            //echo $sql;
            //$data = $this-> conn -> query($sql);

            $_SESSION["user"]=$result['sname'];
            header("location:index.php?c=index&m=start");
          }
          else
          {
            echo "登陆失败！请检查用户名密码是否输入错误！";
            //header("location:index.php?c=index&m=login");
            header("refresh:3;url='index.php?c=index&m=userlog'");
          }
        }
        //管理员登陆
        public function doAdminLogin()
        {
          $result = $this -> mod ->doAdminLoginInfo($_POST);
          if($result == true)
          {
            //var_dump($result);
            //session_start();
            //$sid = $_POST['sid'];
            //$sql = "select * from student where sid='$sid'";
            //echo $sql;
            //$data = $this-> conn -> query($sql);

            //$_SESSION["user"]=$result['sname'];
            header("location:admin/index.php?c=index&m=index");
          }
          else
          {
            echo "登陆失败！请检查管理员用户密码是否输入错误！";
            //header("location:index.php?c=index&m=login");
            header("refresh:3;url='index.php?c=index&m=adminlog'");
          }
        }
        //提交试卷 返回成绩
        public function addtestRtList()
        {
          $result=$this->mod->addTestInfo($_POST);
          if($result == true)
          {
            $data = $this -> mod -> getGradeByName();
            $this -> assign("grade",$data);
            $this -> display();
            //echo '添加成功<br/>';
           // echo '<a href="index.php?c=index&m=orderlist">如果没有跳转，请点这里跳转</a>';
          }
          else
          { 
            echo '添加失败！';
            $this -> display();
            //header("location:index.php?c=index&m=start");
           
          }
        }
        //注销
        public function logout()
        {
          session_start();
          session_destroy();
          header("location:index.php");
        }
   }//class Usercontroller end


?>